import { defHttp } from '@/utils/http/axios';
import { PageResult, Result } from '@/api/model/baseModel';
import { ProductTasksVo } from './model';

const PREFIX = '/productionTasks';
const region = 'cloud-api';

export const tasksProductionApi = {
  /** 查询生产任务分页 */
  query: (params?: any) => {
    return defHttp.post<PageResult<ProductTasksVo>>(
      {
        url: PREFIX + '/queryProductionTasks',
        params,
      },
      {
        region,
      },
    );
  },

  /** 新增生产任务 */
  addProduct: (data: any)=>{
    return defHttp.post<Result<void>>(
      {
        url: PREFIX + '/addProductionTasksService',
        data,
      },
      {
        region,
      },
    );
  },
  /** 修改生产任务 */
  updateProduct: (data: any)=>{
    return defHttp.put<Result<void>>(
      {
        url: PREFIX + '/updateProductionTasksService',
        data,
      },
      {
        region,
      },
    );
  },
  /** 删除生产任务 */
  deleteProduct: (data: any)=>{
    return defHttp.delete<Result<void>>(
      {
        url: PREFIX + '/deleteProductionTasksService',
        data,
      },
      {
        region,
      },
    );
  },

  /** 生产任务审核 */
  examineProduct: (data: any)=>{
    return defHttp.post<Result<void>>(
      {
        url: PREFIX + '/examine',
        data,
      },
      {
        region,
      },
    );
  },
  /** 生成生产单号 */
  getOrderNumber: ()=>{
    return defHttp.get<Result<string>>(
      {
        url: PREFIX + '/getOrderNumber'
      },
      {
        region,
      },
    );
  },
  /** 根据生产任务查询物料 */
  queryMaterialById: (data: any)=>{
    return defHttp.post<Result<any>>(
      {
        url: `${PREFIX}/queryMaterialById`,
        data
      },
      {
        region,
      },
    );
  },
  /** 根据生产任务查询工序 */
  queryProcessById: (data: any)=>{
    return defHttp.post<Result<any>>(
      {
        url: `${PREFIX}/queryProcessById`,
        data
      },
      {
        region,
      },
    );
  },
  /** 领料 */
  receiveMaterials: (data: any)=>{
    return defHttp.post<Result<void>>(
      {
        url: PREFIX + '/receiveMaterials',
        data,
      },
      {
        region,
      },
    );
  },
  /** 退料 */
  returnMaterials: (data: any)=>{
    return defHttp.post<Result<void>>(
      {
        url: PREFIX + '/returnMaterials',
        data,
      },
      {
        region,
      },
    );
  },
  /** 用料 */
  useMaterials: (data: any)=>{
    return defHttp.post<Result<void>>(
      {
        url: PREFIX + '/useMaterials',
        data,
      },
      {
        region,
      },
    );
  },
  /** 验收 */
  checkProcess: (data: any)=>{
    return defHttp.post<Result<void>>(
      {
        url: PREFIX + '/checkProcess',
        data,
      },
      {
        region,
      },
    );
  },
  /** 入库 */
  upStore: (data: any)=>{
    return defHttp.post<Result<void>>(
      {
        url: PREFIX + '/upStore',
        data,
      },
      {
        region,
      },
    );
  },
  /** 完工 */
  completed: (id: any)=>{
    return defHttp.get<Result<void>>(
      {
        url: PREFIX + '/completed/'+ id,
      },
      {
        region,
      },
    );
  },
};
